#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V,d[100010],v[100010],a[100010],p[100010],c[1000010],ans1,ans2,l[21],r[21],num;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>T;
    while(T--)
    {
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        memset(p,0,sizeof(p));
        ans1=ans2=0;
        bool pd=1;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]<0)pd=0;
        }
        for(int i=1;i<=m;i++)
            cin>>p[i];
        sort(p+1,p+m+1);
        if(pd){
            for(int i=1;i<=n;i++)
            {
                if(a[i]==0){
                    if(v[i]>V&&d[i]<=p[m])ans1++;
                }else{
                    long long s=d[i];
                    if(v[i]<V){
                        s+=(double)(V*V-v[i]*v[i])/(2*a[i])+0.999999;
                        }
                    if(s<=p[m])ans1++;
                }
            }
            ans2=m-1;
            if(!ans1)ans2=m;
        }else{
            int ll=0,rr=0;
            for(int i=1;i<=n;i++)
            {
                l[ans1+1]=r[ans1+1]=0;
                if(a[i]==0){
                    if(v[i]>V&&d[i]<=p[m]){ll=d[i];rr=p[m];}
                }
                if(a[i]>0){
                    long long s=d[i];
                    if(v[i]<V){
                        s+=(V*V-v[i]*v[i])/(2*a[i])+1;
                        }
                    if(s<=p[m]){ll=s;rr=p[m];}
                }
                if(a[i]<0){
                    if(v[i]<=V||d[i]>p[m])continue;
                    long long s=d[i]+(v[i]*v[i]-V*V)/(-2*a[i]);
                    if((v[i]*v[i]-V*V)%(-2*a[i])==0)s--;
                    s=min(s,(long long)p[m]);
                    ll=d[i];
                    rr=s;
                }
                for(int j=1;j<=m;j++)
                    if(p[j]>=ll){l[ans1+1]=j;break;}
                for(int j=m;j>=1;j--)
                    if(p[j]<=rr){r[ans1+1]=j;break;}
                if(l[ans1+1]&&l[ans1+1]<=r[ans1+1])ans1++;
            }
            for(int i=0;i<(1<<m);i++)
            {
                int sum=m,pd2=1;
                for(int j=1;j<=ans1;j++)
                    {
                        if(!l[j])continue;
                        num=((1<<(r[j]-l[j]+1))-1)<<(l[j]-1);
                        if(!(num&i)){pd2=0;break;}
                    }
                if(!pd2)continue;
                for(int j=0;j<m;j++)
                    if((1<<j)&i)sum--;
                ans2=max(ans2,sum);
            }
        }
        cout<<ans1<<' '<<ans2<<'\n';
    }
    return 0;
}
